package com.androidtv.pos.adapter;

import android.view.ViewGroup;

import com.androidhelper.module.common.base.BaseFragment;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;


/*
*
* fragment当中添加viewpager+fragment时，viewpager的adapter有一个参数需要填入FragmentManager，\
* 这个manager一定要填入getChildFragmentManager()，而不是getFragmentManager()，否则会造成fragment重复生成无法被销毁

*
* */
public class RightMainFragmentPagerAdapter extends FragmentPagerAdapter {
    private final List<String>  stringArr;
    private final List<BaseFragment> mFragmentList;

    public RightMainFragmentPagerAdapter(@NonNull FragmentManager fm,List<String> titles, List<BaseFragment> mFragmentList) {
        super(fm);

        this.stringArr=titles;
        this.mFragmentList=mFragmentList;
    }



    @Override
    public int getCount() {
        return mFragmentList.size();
    }


    @Override
    public CharSequence getPageTitle(int position) {
        return stringArr.get(position);
    }



    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }


    //注释父类实现，避免出现fragment 空白
    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        //super.destroyItem(container,position,object);
    }




}
